#include <iostream>
#include <string>

struct A {
	A() = default;

	void FuncA() {
		std::cout << "A::FuncA()" << std::endl;
	}
};

struct CA : public A {
	int C{ 10 };
	CA() = default;

	void FuncCA() {
		std::cout << "CA::C :" << C << std::endl;
		std::cout << "CA::FuncCA()" << std::endl;
	}
};

struct Base {
	Base() = default;
	virtual void Func() {
		std::cout << "Base::Func()" << std::endl;
	};
};

struct Derived : public Base {
	int D{ 20 };

	Derived() = default;
	virtual void Func() {
		std::cout << "Derived::Func()" << std::endl;
	};
};


const std::string& ShorterString(const std::string& s1, const std::string& s2) {
	return s1.size() < s2.size() ? s1 : s2;
}

std::string& ShorterString(std::string& s1, std::string& s2) {
	auto& result = ShorterString(const_cast<const std::string&>(s1),
								const_cast<const std::string&>(s2));

	return const_cast<std::string&>(result);
}


int main() {
	float f = 1.0f;
	int i_f = static_cast<int>(f);

	//int* vif = static_cast<int*>(&f);	//error
	void* vf = static_cast<void*>(&f);
	int* vif = static_cast<int*>(vf);

	CA ca;
	A a = static_cast<A>(ca);

	A a1;
	//CA ca1 = static_cast<CA>(a1);

	A a2;
	CA* pa2 = static_cast<CA*>(&a2);
	pa2->FuncCA();

	Base base;
	Derived derived;

	Base* pDerived = static_cast<Base*>(&derived);
	pDerived->Func();

	Derived* pBase = static_cast<Derived*>(&base);
	pBase->Func();
	pBase->D;	//不安全

	Derived* ppDerived = static_cast<Derived*>(pDerived);
	ppDerived->Func();
	
	const char* s = "Hello World";
	char* ss = const_cast<char*>(s);
	//ss[0] = 'h';	//exception

	std::string s1 = "Hi";
	std::string s2 = "World";

	ShorterString(s1, s2);

	int i = 10;
	int* pi = reinterpret_cast<int*>(i);

	float ff = 1.0f;
	int* pfi = reinterpret_cast<int*>(&ff);

	//int64_t cpi = reinterpret_cast<int64_t>(pi);
}